﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using Vouchers;
using System.Collections;

namespace BasicForms
{
    public partial class FrmSupportPrintableComponents : BasicForms.FrmClose
    {
        public FrmSupportPrintableComponents()
        {
            InitializeComponent();
        }

        //Dùng cho các báo cáo dạng Form click ra để mở Form chứng từ luôn
        public DanhSachChungTu _DanhSachChungTu = new DanhSachChungTu();
        public ArrayList listChungTuID = new ArrayList();

        bool _PrintTenCongTy;
        bool _PrintDiaChiDienThoai;
        string _Title = "";
        string _MoreHeader1 = "";
        string _MoreHeader2 = "";
        string _MoreHeader3 = "";
        string _MoreHeader4 = "";
        string _AlignMoreHeader1 = "";
        string _AlignMoreHeader2 = "";
        string _AlignMoreHeader3 = "";
        string _AlignMoreHeader4 = "";
        string _Footer1 = "";
        string _Footer2 = "";
        string _Footer3 = "";
        string _Footer4 = "";
        int _NumberOfLineFooter = 1;
        string _AlignFooter1 = "";
        string _AlignFooter2 = "";
        string _AlignFooter3 = "";
        string _AlignFooter4 = "";

        //For control Dev
        protected void PrintWithHeader(bool useLandscapeView, IPrintable printableComponent, bool printTenCongTy, bool printDiaChiDienThoai, string title, string more1)
        {
            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = more1;

            printableComponentLink.Component = printableComponent;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeader(bool useLandscapeView, IPrintable printableComponent, bool printTenCongTy, bool printDiaChiDienThoai, string title, string more1, string more2)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = more1;
            _MoreHeader2 = more2;

            printableComponentLink.Component = printableComponent;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);

            //printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeaderAndFooter(bool useLandscapeView, IPrintable printableComponent, bool printTenCongTy, bool printDiaChiDienThoai,
            string title, string header1, string header2,
            string footer1, string footer2)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = header1;
            _MoreHeader2 = header2;
            _Footer1 = footer1;
            _Footer2 = footer2;

            printableComponentLink.Component = printableComponent;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeaderAndFooter(bool useLandscapeView, IPrintable printableComponent, bool printTenCongTy, bool printDiaChiDienThoai,
            string title, string header1, string alignHeader1, string header2, string alignHeader2,
            int numberOfLineFooter, string footer1, string alignfooter1, string footer2, string alignfooter2)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = header1;
            _AlignMoreHeader1 = alignHeader1;
            _AlignMoreHeader2 = alignHeader2;
            _MoreHeader2 = header2;
            _Footer1 = footer1;
            _Footer2 = footer2;
            _NumberOfLineFooter = numberOfLineFooter;
            _AlignFooter1 = alignfooter1;
            _AlignFooter2 = alignfooter2;

            printableComponentLink.Component = printableComponent;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeaderAndFooterSoChiTietCongNo(bool useLandscapeView, IPrintable printableComponent, bool printTenCongTy, bool printDiaChiDienThoai,
           string title, string header1, string alignHeader1, string header2, string alignHeader2,
            string header3, string alignHeader3, string header4, string alignHeader4,
            string footer1, string alignfooter1, string footer2, string alignfooter2,
            string footer3, string alignfooter3, string footer4, string alignfooter4)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = header1;
            _MoreHeader2 = header2;
            _MoreHeader3 = header3;
            _MoreHeader4 = header4;
            _AlignMoreHeader1 = alignHeader1;
            _AlignMoreHeader2 = alignHeader2;
            _AlignMoreHeader3 = alignHeader3;
            _AlignMoreHeader4 = alignHeader4;
            _Footer1 = footer1;
            _Footer2 = footer2;
            _Footer3 = footer3;
            _Footer4 = footer4;
            _AlignFooter1 = alignfooter1;
            _AlignFooter2 = alignfooter2;
            _AlignFooter3 = alignfooter3;
            _AlignFooter4 = alignfooter4;

            printableComponentLink.Component = printableComponent;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }


        //For DataTable via GrdiControl Dev
        protected void PrintWithHeader(bool useLandscapeView, DataTable datatable, bool printTenCongTy, bool printDiaChiDienThoai, string title, string more1)
        {
            gridControlPrinting.DataSource = datatable;
            FormatNumberInGridView(gridViewPrinting);  //Để số in ra theo format
            gridViewPrinting.BeginUpdate();
            gridViewPrinting.BestFitColumns();

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = more1;

            printableComponentLink.Component = gridControlPrinting;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeader(bool useLandscapeView, DataTable datatable, bool printTenCongTy, bool printDiaChiDienThoai, string title, string more1, string more2)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            gridControlPrinting.DataSource = datatable;
            FormatNumberInGridView(gridViewPrinting);  //Để số in ra theo format
            gridViewPrinting.BeginUpdate();
            gridViewPrinting.BestFitColumns();

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = more1;
            _MoreHeader2 = more2;

            printableComponentLink.Component = gridControlPrinting;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);

            //printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeaderAndFooter(bool useLandscapeView, DataTable datatable, bool printTenCongTy, bool printDiaChiDienThoai,
            string title, string header1, string header2,
            string footer1, string footer2)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            gridControlPrinting.DataSource = datatable;
            FormatNumberInGridView(gridViewPrinting);  //Để số in ra theo format
            gridViewPrinting.BeginUpdate();
            gridViewPrinting.BestFitColumns();

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = header1;
            _MoreHeader2 = header2;
            _Footer1 = footer1;
            _Footer2 = footer2;

            printableComponentLink.Component = gridControlPrinting;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeaderAndFooter(bool useLandscapeView, DataTable datatable, bool printTenCongTy, bool printDiaChiDienThoai,
            string title, string header1, string alignHeader1, string header2, string alignHeader2,
            int numberOfLineFooter, string footer1, string alignfooter1, string footer2, string alignfooter2)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            gridControlPrinting.DataSource = datatable;
            FormatNumberInGridView(gridViewPrinting);  //Để số in ra theo format
            gridViewPrinting.BeginUpdate();
            gridViewPrinting.BestFitColumns();

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = header1;
            _AlignMoreHeader1 = alignHeader1;
            _AlignMoreHeader2 = alignHeader2;
            _MoreHeader2 = header2;
            _Footer1 = footer1;
            _Footer2 = footer2;
            _NumberOfLineFooter = numberOfLineFooter;
            _AlignFooter1 = alignfooter1;
            _AlignFooter2 = alignfooter2;

            printableComponentLink.Component = gridControlPrinting;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        protected void PrintWithHeaderAndFooterSoChiTietCongNo(bool useLandscapeView, DataTable datatable, bool printTenCongTy, bool printDiaChiDienThoai,
           string title, string header1, string alignHeader1, string header2, string alignHeader2,
            string header3, string alignHeader3, string header4, string alignHeader4,
            string footer1, string alignfooter1, string footer2, string alignfooter2,
            string footer3, string alignfooter3, string footer4, string alignfooter4)
        {
            PageHeaderFooter phf = printableComponentLink.PageHeaderFooter as PageHeaderFooter;
            phf.Footer.Content.Clear();
            string ngay = string.Format("{0}/{1}/{2} {3}:{4}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);
            phf.Footer.Content.AddRange(new string[] { ngay, "", "Trang [Page #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            gridControlPrinting.DataSource = datatable;
            FormatNumberInGridView(gridViewPrinting);  //Để số in ra theo format
            gridViewPrinting.BeginUpdate();
            gridViewPrinting.BestFitColumns();

            _PrintTenCongTy = printTenCongTy;
            _PrintDiaChiDienThoai = printDiaChiDienThoai;
            _Title = title;
            _MoreHeader1 = header1;
            _MoreHeader2 = header2;
            _MoreHeader3 = header3;
            _MoreHeader4 = header4;
            _AlignMoreHeader1 = alignHeader1;
            _AlignMoreHeader2 = alignHeader2;
            _AlignMoreHeader3 = alignHeader3;
            _AlignMoreHeader4 = alignHeader4;
            _Footer1 = footer1;
            _Footer2 = footer2;
            _Footer3 = footer3;
            _Footer4 = footer4;
            _AlignFooter1 = alignfooter1;
            _AlignFooter2 = alignfooter2;
            _AlignFooter3 = alignfooter3;
            _AlignFooter4 = alignfooter4;

            printableComponentLink.Component = gridControlPrinting;
            printableComponentLink.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink.Landscape = useLandscapeView;
            printableComponentLink.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            printableComponentLink.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);
            printableComponentLink.CreateDocument();
            printableComponentLink.ShowPreview();
        }

        //Header
        private void printableComponentLink_CreateReportHeaderArea(object sender, CreateAreaEventArgs e)
        {
            try
            {
                int currentY = 0;

                if (_PrintTenCongTy)
                {
                    string tenCongTy = GeneralLibs.Config.TenDoanhNghiep;
                    e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);
                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rectCongTy = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 20);
                    currentY += 20;
                    e.Graph.DrawString(tenCongTy, Color.Black, rectCongTy, BorderSide.None);
                }
                if (_PrintDiaChiDienThoai)
                {
                    //Địa chỉ
                    string diaChi = string.Format("Địa chỉ: {0}", GeneralLibs.Config.DiaChi);
                    e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);
                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rectDiaChi = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 20);
                    currentY += 20;
                    e.Graph.DrawString(diaChi, Color.Black, rectDiaChi, BorderSide.None);
                    //Điện thoại
                    string dienThoai = string.Format("Điện thoại: {0}", GeneralLibs.Config.DienThoai);
                    e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);
                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rectDienThoai = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 30);
                    currentY += 30;
                    e.Graph.DrawString(dienThoai, Color.Black, rectDienThoai, BorderSide.None);
                }

                if (_Title.Length > 0)
                {
                    e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                    e.Graph.Font = new Font("Tahoma", 14, FontStyle.Bold);
                    RectangleF rec = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 30);
                    currentY += 30;
                    e.Graph.DrawString(_Title, Color.Black, rec, BorderSide.None);
                }
                if (_MoreHeader1.Length > 0)
                {
                    if (_AlignMoreHeader1.ToUpper() == "CENTER")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                    else if (_AlignMoreHeader1.ToUpper() == "RIGHT")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                    else
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);

                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 20);
                    currentY += 20;
                    e.Graph.DrawString(_MoreHeader1, Color.Black, rect, BorderSide.None);
                }
                if (_MoreHeader2.Length > 0)
                {
                    if (_AlignMoreHeader2.ToUpper() == "CENTER")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                    else if (_AlignMoreHeader2.ToUpper() == "RIGHT")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                    else
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);

                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 20);
                    currentY += 20;
                    e.Graph.DrawString(_MoreHeader2, Color.Black, rect, BorderSide.None);
                }
                if (_MoreHeader3.Length > 0)
                {
                    if (_AlignMoreHeader3.ToUpper() == "CENTER")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                    else if (_AlignMoreHeader3.ToUpper() == "RIGHT")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                    else
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);

                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 20);
                    currentY += 20;
                    e.Graph.DrawString(_MoreHeader3, Color.Black, rect, BorderSide.None);
                }
                if (_MoreHeader4.Length > 0)
                {
                    if (_AlignMoreHeader4.ToUpper() == "CENTER")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                    else if (_AlignMoreHeader4.ToUpper() == "RIGHT")
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                    else
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);

                    e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                    RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 20);
                    currentY += 20;
                    e.Graph.DrawString(_MoreHeader4, Color.Black, rect, BorderSide.None);
                }
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
        }

        //Footer
        private void printableComponentLink_CreateReportFooterArea(object sender, CreateAreaEventArgs e)
        {
            try
            {
                int currentY = 25;  //Nghĩa là footer1 cách gridcontrol 25 đơn vị

                e.Graph.BackColor = Color.White;
                //Nếu có ít hơn 2 Footer 
                if ((_Footer1 != "" && _Footer2 != "") && _Footer3 == "" && _Footer4 == "")
                {
                    if (_NumberOfLineFooter == 2)
                    {
                        if (_Footer1.Length > 0)
                        {
                            if (_AlignFooter1.ToUpper() == "CENTER")
                                e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                            else if (_AlignFooter1.ToUpper() == "RIGHT")
                                e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                            else
                                e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);

                            e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                            RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 30);
                            currentY += 30;
                            e.Graph.DrawString(_Footer1, Color.Black, rect, BorderSide.None);
                        }
                        if (_Footer2.Length > 0)
                        {
                            if (_AlignFooter2.ToUpper() == "CENTER")
                                e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                            else if (_AlignFooter2.ToUpper() == "RIGHT")
                                e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                            else
                                e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Near);
                            e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                            RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 90);
                            currentY += 20;
                            e.Graph.DrawString(_Footer2, Color.Black, rect, BorderSide.None);
                        }
                    }
                    else
                    {
                        //e.Graph.BackColor = Color.White;
                        if (_Footer1.Length > 0)
                        {
                            e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                            e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                            RectangleF rect = new RectangleF(0, 30, 410, 90);
                            e.Graph.DrawString(_Footer1, Color.Black, rect, BorderSide.None);
                        }
                        if (_Footer2.Length > 0)
                        {
                            e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                            e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                            RectangleF rect = new RectangleF(600, 30, 300, 90);
                            e.Graph.DrawString(_Footer2, Color.Black, rect, BorderSide.None);
                        }
                    }
                }
                else if (_Footer1 != "" && _Footer2 != "" || _Footer3 == "")    //Nếu mà nhiều hơn 2 footer (3 hoặc 4)
                {
                    //Thứ tự sắp xếp - cho sổ chi tiết công nợ
                    //                          footer 1
                    //footer 2
                    //footer 3              footer 4
                    currentY = 10;
                    if (_Footer1.Length > 0)
                    {
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Far);
                        e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                        RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 30);
                        e.Graph.DrawString(_Footer1, Color.Black, rect, BorderSide.None);
                    }
                    currentY += 20;

                    if (_Footer2.Length > 0)
                    {
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                        e.Graph.Font = new Font("Times New Roman", 13, FontStyle.Italic);
                        RectangleF rect = new RectangleF(0, currentY, e.Graph.ClientPageSize.Width, 30);
                        e.Graph.DrawString(_Footer2, Color.Black, rect, BorderSide.None);
                    }
                    currentY += 30;

                    if (_Footer3.Length > 0)
                    {
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                        e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                        RectangleF rect = new RectangleF(0, currentY, 500, 90);
                        e.Graph.DrawString(_Footer3, Color.Black, rect, BorderSide.None);
                    }
                    if (_Footer4.Length > 0)
                    {
                        e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center);
                        e.Graph.Font = new Font("Times New Roman", 12, FontStyle.Regular);
                        RectangleF rect = new RectangleF(600, currentY, 300, 90);
                        e.Graph.DrawString(_Footer4, Color.Black, rect, BorderSide.None);
                    }
                }
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
        }
    }
}
